package org.tea.inventory.model.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.tea.inventory.base.util.StringUtils;
import org.tea.inventory.base.validation.groups.CreateGroup;
import org.tea.inventory.base.validation.groups.UpdateGroup;
import org.tea.inventory.base.validation.groups.warehouse.*;
import org.tea.inventory.db.domain.Storage;
import org.tea.inventory.domain.tea.WarehouseInventorySerialInfo;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 仓库库存流水对象 warehouse_inventory_serial
 * 
 * @author dongxb
 * @date 2025-04-16
 */
@ApiModel(value = "仓库库存流水Vo对象")
@Data
@NoArgsConstructor
public class WarehouseInventorySerialVo implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 主键 */
    private Long id;

    /** 流水编号 */
    @ApiModelProperty(name = "流水编号")
    private String serialCode;

    /** 本仓库/调出仓库id */
    @ApiModelProperty(name = "本仓库/调出仓库id")
    private Long warehouseId;

    /** 本仓库/调出仓库名称 */
    @ApiModelProperty(name = "本仓库/调出仓库名称")
    private String warehouseName;

    /** 供应商id */
    @ApiModelProperty(name = "供应商id")
    private Long supplierId;

    /** 供应商名称 */
    @ApiModelProperty(name = "供应商名称")
    private String supplierName;

    /** 流水类型 0库存盘点单，1入库单，2出库单，3调拨单，4换货单，5报损单，6包装/组装单，7拆包/拆卸单 */
    @ApiModelProperty(name = "流水类型 0库存盘点单，1入库单，2出库单，3调拨单，4换货单，5报损单，6包装/组装单，7拆包/拆卸单")
    private String serialType;

    /** 拓展字段，可用可不用。 库存流水状态：0启用，1停用 */
    @ApiModelProperty(name = "拓展字段，可用可不用。 库存流水状态：0启用，1停用")
    private Integer status;

    /** 是否删除：0未删除，1已删除 */
    @ApiModelProperty(value = "是否删除： 0未删除，1已删除")
    private Integer delFlag;

    /** 目标仓库/调出仓库id */
    @ApiModelProperty(name = "目标仓库/调出仓库id")
    private Long warehouseTargetId;

    /** 目标仓库/调出仓库名称 */
    @ApiModelProperty(name = "目标仓库/调出仓库名称")
    private String warehouseTargetName;

    /** 入库/经手人id */
    @ApiModelProperty(name = "入库/调入经手人id")
    private String addHandlerId;

    /** 入库/经手人id */
    @ApiModelProperty(name = "出库/调出经手人id")
    private String outHandlerId;

    /** 入库/经手人id */
    @ApiModelProperty(name = "出库/调出经手人名称")
    private String outHandlerName;

    /** 入库/经手人名称 */
    @ApiModelProperty(name = "入库/经手人名称")
    private String addHandlerName;

    /** 单据时间(入库/要货/调拨/换货时间等) */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(name = "单据时间(入库/要货/调拨/换货时间等)")
    private Date serialDate;
    private String serialDateStr;

    /** 换货人id */
    @ApiModelProperty(name = "换货人id")
    private String updateUserId;

    /** 换货人名称 */
    @ApiModelProperty(name = "换货人名称")
    private String updateUserName;

    /** 要货部门id */
    @ApiModelProperty(name = "要货部门id")
    private Long requireDepartmentId;

    /** 要货部门名称 */
    @ApiModelProperty(name = "要货部门名称")
    private String requireDepartmentName;

    /** 组装商品名称 */
    @ApiModelProperty(name = "组装商品id")
    private Long assembleProductId;

    /** 组装商品名称 */
    @ApiModelProperty(name = "组装商品名称")
    private String assembleProductName;

    /** 组装商品名称 */
    @ApiModelProperty(name = "组装/拆卸数量")
    private Integer updateNumber;

    /** 组装商品名称 */
    @ApiModelProperty(name = "报损类型")
    private String breakType;

    /** 门店id */
    @ApiModelProperty(name = "门店id")
    private Long storeId;

    /** 门店名称 */
    @ApiModelProperty(name = "门店名称")
    private String storeName;

    /** 是否执行完毕/入库状态：0执行完毕，1未执行 */
    @ApiModelProperty(name = "是否执行完毕/入库状态：0执行完毕，1未执行")
    private Integer isRunFinish;
    private String isRunFinishStr;

    /** 是否已经发货/发货状态：0已发货，1待发货 */
    @ApiModelProperty(name = "是否已经发货/发货状态：0已发货，1待发货")
    private Integer isDelivery;

    /** 备注/报损原因/换货原因 */
    @NotBlank(message = "备注或原因不能为空" , groups = {OutGroup.class , RequisitionGroup.class , SwapGroup.class , BreakageGroup.class})
    @ApiModelProperty(name = "备注/报损原因/换货原因")
    private String remarks;

    /** 组装/拆解原因 */
    @NotBlank(message = "备注不能为空2" , groups = {UpdateGroup.class , CreateGroup.class})
    @ApiModelProperty(name = "组装/拆解原因")
    private String reason;

    /** 作废原因 */
    @ApiModelProperty(name = "作废原因")
    private String cancelMsg;

    /** 附件ids */
    @ApiModelProperty(name = "附件文件id")
    private String fileIds;

    @ApiModelProperty(value = "附件文件信息")
    private List<Storage> files;

    /** 创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(name = "创建时间")
    private Date createDate;

    /** 创建者 */
    @ApiModelProperty(name = "创建者")
    private String createUser;

    /** 更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(name = "更新时间")
    private Date updateDate;

    /** 更新者 */
    @ApiModelProperty(name = "更新者")
    private String updateUser;

    @Valid
    @NotNull(groups = {EntryGroup.class , RequisitionGroup.class , SwapGroup.class})
    @ApiModelProperty(value = "入库明细")
    List<WarehouseInventorySerialInfo> inventoryEntryInfos;

    @Valid
    @NotNull(groups = {OutGroup.class , SwapGroup.class , BreakageGroup.class})
    @ApiModelProperty(value = "出库明细")
    List<WarehouseInventorySerialInfo> inventoryOutInfos;

    //查询字段
    //开始时间
    @ApiModelProperty(name = "开始时间")
    private String startDate;

    //结束时间
    @ApiModelProperty(name = "结束时间")
    private String endDate;

    public void setEndDate(String endDate) {
        if (StringUtils.isNotBlank(endDate)) endDate = endDate + " 23:59:59";
        this.endDate = endDate;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("serialCode", getSerialCode())
                .append("warehouseId", getWarehouseId())
                .append("supplierId", getSupplierId())
                .append("serialType", getSerialType())
                .append("status", getStatus())
                .append("warehouseTargetId", getWarehouseTargetId())
                .append("addHandlerId", getAddHandlerId())
                .append("serialDate", getSerialDate())
                .append("updateUserId", getUpdateUserId())
                .append("requireDepartmentId", getRequireDepartmentId())
                .append("assembleProductId", getAssembleProductId())
                .append("assembleProductName", getAssembleProductName())
                .append("updateNumber", getUpdateNumber())
                .append("storeId", getStoreId())
                .append("isRunFinish", getIsRunFinish())
                .append("isDelivery", getIsDelivery())
                .append("remarks", getRemarks())
                .append("updateNumber", getUpdateNumber())
                .append("breakType", getBreakType())
                .append("reason", getReason())
                .append("fileIds", getFileIds())
                .append("createDate", getCreateDate())
                .append("createUser", getCreateUser())
                .append("updateDate", getUpdateDate())
                .append("updateUser", getUpdateUserId())
                .append("inventoryEntryInfos", getInventoryEntryInfos())
                .append("inventoryOutInfos", getInventoryOutInfos())
                .append("startDate", getStartDate())
                .append("endDate", getEndDate())
                .toString();
    }
}
